package com.yunbiao.ybbusstopplate.ui.view.subway;

import android.content.Context;
import android.graphics.*;
import android.view.View;
import androidx.core.view.ViewCompat;

import com.blankj.utilcode.util.ImageUtils;
import com.yunbiao.ybbusstopplate.BuildConfig;
import com.yunbiao.ybbusstopplate.R;
import com.yunbiao.ybbusstopplate.ui.activity.FlavorType;

import java.util.List;


/* renamed from: com.tmindtech.subway.ui.StationMap */
public class StationMap2 extends View {
    private static final String TAG = "StationMap2";
    public static int STATIONMAP_FLAGHEIGHT = 60;
//    public static int STATIONMAP_MAXFONTSIZE = 36;
    public static int STATIONMAP_MAXFONTSIZE = 34;
    public static String Symbol = "..........";
    private int MapCount;
    //    private String[] NameString;
    private List<String[]> NameString;
    private int StationCur;
    private int StationMap_height;
    private int StationMap_width;
    private int StationNum;
    private Paint StrPaint;
    private int SymbolWidth;
    private int stylecolor;
    private float y_offset;
    private int limitStationNum=50;

    public StationMap2(Context context, List<String[]> strlist, int limitStationNum) {
        super(context);
        this.limitStationNum=limitStationNum;
        varInit(strlist);
    }

    private void varInit(List<String[]> strlist) {
        this.StationMap_width = 1920;
        this.StationMap_height = 400;
        this.StationNum = strlist.size();
        this.StationCur = 0;
        this.NameString = strlist;
        this.StrPaint = new Paint();
        AutoSetSize();
        this.stylecolor = Color.argb(255, 230, 255, 230);
    }

    private void AutoSetSize() {
        if (this.StationNum <= limitStationNum) {
            this.MapCount = NameString.size();
            this.SymbolWidth = 0;
        } else {
            this.MapCount = 16;
            this.SymbolWidth = 120;
        }
        this.y_offset = ((float) ((this.StationMap_width - 80) - this.SymbolWidth)) / ((float) this.MapCount);
        if (this.y_offset - 2.0f > ((float) STATIONMAP_MAXFONTSIZE)) {
            this.StrPaint.setTextSize((float) STATIONMAP_MAXFONTSIZE);
        } else {
            this.StrPaint.setTextSize(this.y_offset - 2.0f);
        }
    }

    private void drawStationNameText(Canvas canvas, float offset, int index) {
        float ascent;
        float descent;
        float mFontHeight;
        float h_Spacing=2.0f;
        float h_offset;
        String[] array = this.NameString.get(index);
        index=Integer.parseInt(array[0]);
        String text=array[1];
//        String text = this.NameString[index];
        this.StrPaint.setTextAlign(Paint.Align.CENTER);
        this.StrPaint.setAntiAlias(true);
        float fontsize = this.StrPaint.getTextSize();
        do {
            Paint.FontMetrics fm = this.StrPaint.getFontMetrics();
            ascent = fm.ascent;
            descent = fm.descent;
            mFontHeight = (float) Math.ceil((double) (descent - ascent));
            if(BuildConfig.FLAVOR_TYPE == FlavorType.LESHAN){
                h_Spacing = 0;
            } else {
                h_Spacing = (((float) ((this.StationMap_height - STATIONMAP_FLAGHEIGHT) - 30)) - (((float) text.length()) * mFontHeight)) / ((float) (text.length() - 1));
            }
            h_offset = (((float) ((this.StationMap_height - STATIONMAP_FLAGHEIGHT) - 30)) - mFontHeight) / ((float) (text.length() - 1));
            if (h_offset <= this.StrPaint.getTextSize()) {
                this.StrPaint.setTextSize(this.StrPaint.getTextSize() - 1.0f);
            }
        } while (h_offset <= this.StrPaint.getTextSize());
        if (index < this.StationCur) {
//            this.StrPaint.setColor(Color.parseColor("#898989"));



            this.StrPaint.setColor(Color.parseColor("#8E8E8E"));
        } else if (index == this.StationCur) {
            Paint rectPaint = new Paint();
            rectPaint.setStyle(Paint.Style.FILL);
//            rectPaint.setColor(Color.parseColor("#EB6100"));

            rectPaint.setColor(Color.parseColor("#C52B24"));
//            canvas.drawRoundRect(new RectF((offset - (this.StrPaint.getTextSize() / 2.0f)) - 3.0f, (float) (STATIONMAP_FLAGHEIGHT - 5), (this.StrPaint.getTextSize() / 2.0f) + offset + 3.0f, (float) (this.StationMap_height - 25)), this.StrPaint.getTextSize() / 2.0f, this.StrPaint.getTextSize() / 2.0f, rectPaint);
            canvas.drawRoundRect(new RectF((offset - (this.StrPaint.getTextSize() / 2.0f)) - 3.0f, (float) (STATIONMAP_FLAGHEIGHT - 5), (this.StrPaint.getTextSize() / 2.0f) + offset + 3.0f, (float) (this.StationMap_height - 25)), 5f, 5f, rectPaint);

            this.StrPaint.setColor(Color.parseColor("#ffffff"));
        } else {
            this.StrPaint.setColor(Color.parseColor("#121212"));
        }
        float y = (float) STATIONMAP_FLAGHEIGHT;
        for (int n = 0; n < text.length(); n++) {
            char ch = text.charAt(n);
            if (ch == 65288 || ch == 65289 || ch == '(' || ch == ')') {
                Path path = new Path();
                path.moveTo(offset, y - h_Spacing);
                path.lineTo(offset, y + mFontHeight);
                canvas.drawTextOnPath(String.valueOf(ch), path, 0.0f, descent, this.StrPaint);
            } else {
                Canvas canvas2 = canvas;
                float f = offset;
                canvas2.drawText(String.valueOf(ch), f, y - ascent, this.StrPaint);
            }
            y += h_Spacing + mFontHeight;
        }
        float r = (this.y_offset / 2.0f) - 2.0f;
        if (r > 12.0f) {
            r = 12.0f;
        }
        float cx = offset;
        Paint flagpaint = new Paint();
        flagpaint.setAntiAlias(true);
        if (index < this.StationCur) {
            //绘制外圆
            flagpaint.setColor(Color.parseColor("#E2E2E2"));
            canvas.drawCircle(cx, 30.0f, r, flagpaint);
            //绘制内圆
            flagpaint.setColor(Color.parseColor("#B5B5B5"));
            canvas.drawCircle(cx, 30.0f, (3.0f * r) / 5.0f, flagpaint);
        }


        else if (index == this.StationCur) {
            float currR = r  * 1.8f;
            //绘制外圆
            flagpaint.setColor(Color.parseColor("#EB6100"));
            canvas.drawCircle(cx, 30.0f, currR, flagpaint);
            //绘制内圆
//            flagpaint.setColor(Color.parseColor("#EB6100"));
//            canvas.drawCircle(cx, 30.0f, (3.0f * r) / 5.0f, flagpaint);
            //绘制箭头
            Bitmap bitmap = ImageUtils.getBitmap(R.mipmap.icon_right, (int) (currR * 2), (int) (currR * 2));
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            float bX = cx - width / 2;
            float bY = 30.0f - height / 2;
            canvas.drawBitmap(bitmap,bX,bY,new Paint());
        }

        else {
            //绘制外圆
            flagpaint.setColor(Color.parseColor("#E2E2E2"));
            canvas.drawCircle(cx, 30.0f, r, flagpaint);
            if (index==this.StationCur+1){
                GlobalSetting.getInstance().icon_x = cx;
                GlobalSetting.getInstance().icon_y = 30.0f;
                GlobalSetting.getInstance().icon_r = (3.0f * r) / 5.0f;
            }
            //绘制内圆
            flagpaint.setColor(Color.parseColor("#1EEA67"));
            canvas.drawCircle(cx, 30.0f, (3.0f * r) / 5.0f, flagpaint);
        }
        this.StrPaint.setTextSize(fontsize);
    }

    private void drawSymbol(Canvas canvas, float offset, String str) {
        if (str.length() != 0) {
            float fontsize = this.StrPaint.getTextSize();
            this.StrPaint.setColor(ViewCompat.MEASURED_STATE_MASK);
            this.StrPaint.setTextAlign(Paint.Align.CENTER);
            this.StrPaint.setTextSize(40.0f);
            canvas.drawText(str, offset, ((((float) this.StationMap_height) - fontsize) + ((float) STATIONMAP_FLAGHEIGHT)) / 2.0f, this.StrPaint);
            this.StrPaint.setTextSize(fontsize);
            this.StrPaint.setTextAlign(Paint.Align.LEFT);
        }
    }

    private void drawArriveStationFlag(Canvas canvas, float offset){
        Paint paint = new Paint();
        paint.setAntiAlias(true);


//
        paint.setColor(Color.parseColor("#EB0000"));
        if (this.StationCur==this.StationNum-1){
//            canvas.drawRoundRect(new RectF(40.0f, 25.0f, (float) (this.StationMap_width - 40), 35.0f), 5.0f, 5.0f, paint);
            canvas.drawRoundRect(new RectF(20.0f, 25.0f, (float) (this.StationMap_width - 20), 35.0f), 5.0f, 5.0f, paint);
        }else {
//            canvas.drawRoundRect(new RectF(40.0f, 25.0f, offset, 35.0f), 5.0f, 5.0f, paint);
            canvas.drawRoundRect(new RectF(20.0f, 25.0f, offset, 35.0f), 5.0f, 5.0f, paint);
        }
    }

    private void drawStationFlag(Canvas canvas) {
        Paint flagpaint = new Paint();
        flagpaint.setAntiAlias(true);
//        flagpaint.setColor(Color.parseColor("#B5B5B5"));
        flagpaint.setColor(Color.parseColor("#16bb51"));
//        canvas.drawRoundRect(new RectF(40.0f, 25.0f, (float) (this.StationMap_width - 40), 35.0f), 5.0f, 5.0f, flagpaint);
        canvas.drawRoundRect(new RectF(20.0f, 25.0f, (float) (this.StationMap_width - 20), 35.0f), 5.0f, 5.0f, flagpaint);
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#ffffff"));
        canvas.drawRect(new Rect(0, 0, this.StationMap_width, this.StationMap_height), paint);
        drawStationFlag(canvas);
        if (this.SymbolWidth == 0) {
            //红线绘制
            for (int i = 0; i < this.MapCount; i++) {
                String[] array = this.NameString.get(i);
                int index = Integer.parseInt(array[0]);
                if (index==this.StationCur){
                    drawArriveStationFlag(canvas,(this.y_offset * ((float) i)) + 50.0f + (this.y_offset / 2.0f));
                    break;
                }
            }
            for (int i = 0; i < this.MapCount; i++) {
                drawStationNameText(canvas, (this.y_offset * ((float) i)) + 50.0f + (this.y_offset / 2.0f), i);
            }
        } else if (this.StationCur <= 8) {
            //红线绘制:左侧
            for (int i = 0; i < 15; i++) {
                if (i==this.StationCur){
                    drawArriveStationFlag(canvas,(this.y_offset * ((float) i)) + 50.0f + (this.y_offset / 2.0f));
                }
            }
            //绘制文字
            for (int i2 = 0; i2 < 15; i2++) {
                drawStationNameText(canvas, (this.y_offset * ((float) i2)) + 50.0f + (this.y_offset / 2.0f), i2);
            }
            drawSymbol(canvas, 110.0f + (this.y_offset * 15.0f), Symbol);
            drawStationNameText(canvas, (this.y_offset * 15.0f) + 170.0f + (this.y_offset / 2.0f), this.StationNum - 1);
        } else if (this.StationCur + 7 < this.StationNum - 1) {
            drawStationNameText(canvas, (this.y_offset / 2.0f) + 50.0f, 0);
            int len = ((this.StationCur - 10) * 8) / (this.StationNum - this.MapCount);
            int len2 = len > 8 ? 9 : len + 1;
            drawSymbol(canvas, this.y_offset + 50.0f + ((float) (len2 * 6)), Symbol.substring(0, len2));
            int left = this.StationCur - 6;
            int right = this.StationCur + 8;
            //绘制红线 中间
            for (int i3 = left; i3 < right; i3++) {
                if (i3==this.StationCur){
                    drawArriveStationFlag(canvas,((float) ((len2 * 12) + 50)) + (this.y_offset * ((float) ((i3 + 1) - left))) + (this.y_offset / 2.0f));
                    break;
                }
            }
            for (int i3 = left; i3 < right; i3++) {
                drawStationNameText(canvas, ((float) ((len2 * 12) + 50)) + (this.y_offset * ((float) ((i3 + 1) - left))) + (this.y_offset / 2.0f), i3);
            }
            drawSymbol(canvas, ((float) ((len2 * 6) + 110)) + (this.y_offset * 15.0f), Symbol.substring(len2, 10));
            drawStationNameText(canvas, (this.y_offset * 15.0f) + 170.0f + (this.y_offset / 2.0f), this.StationNum - 1);
        } else {
            drawStationNameText(canvas, (this.y_offset / 2.0f) + 50.0f, 0);
            drawSymbol(canvas, 110.0f + this.y_offset, Symbol);
            //绘制红线 右侧
            for (int i4 = this.StationNum - 15; i4 < this.StationNum; i4++) {
                if (i4==this.StationCur){
                    drawArriveStationFlag(canvas,(this.y_offset * ((float) ((i4 - this.StationNum) + 16))) + 170.0f + (this.y_offset / 2.0f));
                    break;
                }
            }
            for (int i4 = this.StationNum - 15; i4 < this.StationNum; i4++) {
                drawStationNameText(canvas, (this.y_offset * ((float) ((i4 - this.StationNum) + 16))) + 170.0f + (this.y_offset / 2.0f), i4);
            }
        }
    }

    /* access modifiers changed from: protected */
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(this.StationMap_width, this.StationMap_height);
    }

    public void setWidth_Height(int w, int h) {
        this.StationMap_width = w;
        this.StationMap_height = h;
        AutoSetSize();
        postInvalidate();
    }

    public void SetStationNum(int sum) {
        this.StationNum = sum;
        AutoSetSize();
        postInvalidate();
    }

    public boolean SetStationCur(int id) {
        if (id >= this.StationNum) {
            return false;
        }
        this.StationCur = id;
        postInvalidate();
        return true;
    }
}
